package org.springframework.samples.countries.web.translate;

import java.util.List;
import java.util.Stack;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import pikes.ecma.IMemberExpression;
import pikes.ecma.MemberPropertyAccess;

public class GetField implements ByteCodeOperation {

	protected static final Log translatorLogger = LogFactory.getLog("Translator");

	private String name = null;

	public GetField(String name) {
		super();
		this.name = name;
	}

	public void execute(int numberOfParameters, Stack<Object> stack, List<String> localVariables) {
		translatorLogger.info("GETFIELD: Accessing field '" + name + "'");

		IMemberExpression memberExpression = (IMemberExpression) stack.pop();
		stack.push(new MemberPropertyAccess(memberExpression, name));

	}

	@Override
	public String toString() {
		return "getfield " + name;
	}
}
